package com.hh.demo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class Main extends JFrame
{
    public static void main(String[] args)
    {
        new Login();
    }

    Container container;
    public Main()
    {
        this.setTitle("算法设计与分析课程设计系统");
        this.setLocation(600, 250);
        container = this.getContentPane();
        container.setLayout(new BorderLayout());
        JMenuBar menuBar = new JMenuBar();
        buildMainMenu(menuBar);


        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JTextArea textArea = new JTextArea();
        textArea.setText("欢迎来到算法设计与分析课程设计系统");
        textArea.setFont(new Font("宋体", Font.PLAIN, 20));
        panel.add(textArea);

        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setContentPane(panel);
        this.setJMenuBar(menuBar);
        this.setVisible(true);
        this.setSize(600,450);

        this.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosing(WindowEvent e)
            {
                setVisible(false);
                JFrame frame=new JFrame();
                JPanel jp=new JPanel();
                JLabel jl = new JLabel();
                jl.setIcon(new ImageIcon("D:\\1.jpg"));
                jl.setBackground(Color.BLACK);

                jp.add(jl);
                frame.add(jp);

                frame.setTitle("结语");
                frame.setLocation(600, 250);
                frame.setLayout(new FlowLayout());
                frame.setSize(280, 300);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
                frame.addWindowListener(new WindowAdapter(){
                    @Override
                    public void windowClosing(WindowEvent e) {
                        dispose();
                        System.exit(0);
                    }
                });
            }
        });

    }

    public void buildMainMenu(JMenuBar menuBar)
    {
        JMenu fileMenu = new JMenu("文件(F)");//第一个菜单
        JMenuItem exitMenuItem = new JMenuItem("退出");
        exitMenuItem.addActionListener(new ExitActionListener());
        fileMenu.add(exitMenuItem);
        menuBar.add(fileMenu);

        JMenu AlgMenu = new JMenu("算法(A)");//第二个菜单
        AlgMenu.setMnemonic(KeyEvent.VK_A);//给菜单定义助记键
        JMenuItem AlgItem = new JMenuItem("算法目录");
        AlgItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,ActionEvent.CTRL_MASK));//设定快捷键
        AlgItem.addActionListener(new AlgItemActionListener());
        AlgMenu.add(AlgItem);
        menuBar.add(AlgMenu);

        JMenu helpMenu = new JMenu("帮助(H)");//第三个菜单
        helpMenu.setMnemonic(KeyEvent.VK_H);
        JMenuItem aboutMenuItem = new JMenuItem("关于");
        aboutMenuItem.setMnemonic(KeyEvent.VK_M);
        aboutMenuItem.addActionListener(new AboutActionListener());
        helpMenu.add(aboutMenuItem);
        menuBar.add(helpMenu);
    }

    class AlgItemActionListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            new Algorithm();
        }
    }

    class AboutActionListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            String msg = "算法设计与分析课程设计系统\n设计人：曾吉平 康富成 李建鸿 郭亮";
            String title = "关于";
            JOptionPane.showMessageDialog(container, msg,title,JOptionPane.INFORMATION_MESSAGE);
        }
    }

    class ExitActionListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            JFrame frame=new JFrame();
            JPanel jp=new JPanel();
            JLabel jl = new JLabel();
            jl.setIcon(new ImageIcon("D:\\1.jpg"));
            jl.setBackground(Color.BLACK);

            jp.add(jl);
            frame.add(jp);

            frame.setTitle("结语");
            frame.setLocation(600, 250);
            frame.setLayout(new FlowLayout());
            frame.setSize(280, 300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.addWindowListener(new WindowAdapter(){
                @Override
                public void windowClosing(WindowEvent e) {
                    dispose();
                    System.exit(0);
                }
            });
        }
    }

}
